package io.g740.handler;

import io.g740.enums.DataMigrationType;
import io.g740.service.MigrationConfig;

import java.sql.Connection;
import java.sql.SQLException;

public class CalculatorContext {
	private DataMigrationHandler strategy;

	public CalculatorContext(MigrationConfig migrationConfig) {
		if (
				DataMigrationType.FULL_QUANTITY_RESERVED ==
						migrationConfig.getType()) {
			this.strategy = new FullQuantityReservedDataMigrationHandler();
		} else if (
				DataMigrationType.FULL_QUANTITY_NOT_RESERVED ==
						migrationConfig.getType()
		) {
			this.strategy = new FullQuantityNotReservedDataMigrationHandler();
		}
	}

	public boolean migrate(MigrationConfig migrationConfig,
						   Connection sourceConn,
						   Connection targetConn) throws SQLException {
		if (null == strategy) {
			throw new IllegalArgumentException("strategy not set");
		}
		return strategy.migrate(migrationConfig, sourceConn, targetConn);
	}
}